﻿//===========================页面事件动作==============================
//window_onload
//window_onbeforeunload



function window_onload() 
{    
	//1 检测 PsrView 版本
	checkPsrviewVersion(MyZip);

	//2 处理菜单
	document.all("dvmenu").innerHTML = XmlFileToHTML(Form1.txtMenuXml.value, "/report/rptxsl/menu.xsl");

	  
    if(doLoad()=="paramok")
    {
    
         GetRpt();
         
        //打开报表
        //doLoad();
    }
    
    //modified by chenyong 2011-02-18 DSS报表则不显示关闭按钮和下面的行。
    var txtIsDssRpt=document.getElementById("txtIsDssRpt");
    if(txtIsDssRpt && txtIsDssRpt.value=="1")
    {
        var td_exit= document.getElementById("tb_exit");
        var tr_bottom=document.getElementById("trbottom");
        
        if(tr_bottom && td_exit)
        {
            td_exit.style.display="none";
            tr_bottom.style.display="none";
        }
    }   
   
}


//通过通道获取报表信息
function GetRpt()
{
	//如果选择了参数后打开报表，则通过通道获取报表信息
	var sDataXml, sRtnXml;
	//
	if (document.all("txtOpenType").value != "Print" && document.all("txtOpenType").value != "") {
	    document.all("dw_1").style.display = "none";
	    document.all("dw_1").style.backgroundColor = "#ffffff";
	    sDataXml = "<xml><MyRptId>" + document.all("txtRptId").value + "</MyRptId>"
                    + "<MyCustomParam>" + document.all("txtCustomParam").value.replace(/<xml>/g, "<xmlSub000>").replace(/<\/xml>/g, "</xmlSub000>") + "</MyCustomParam>"
                    + "<MyGeneralParam>" + document.all("txtGeneralParam").value.replace(/<xml>/g, "<xmlSub001>").replace(/\</g, "&lt;").replace(/\>/g, "&gt;") + "</MyGeneralParam>"
                    + "<MyExtendData>" + document.all("txtExtendData").value.replace(/<xml>/g, "<xmlSub002>").replace(/<\/xml>/g, "</xmlSub002>") + "</MyExtendData>"
                    + "</xml>";

	    CreateLoadingDiv("正在加载报表，请等待", document, 320);

	    GetDataByXMLHTTPAsync("/Pub_XmlHttp.aspx", "GetRpt", "", sDataXml);
	}
	else {
	    doLoad();
	}
	
	
}
//胡智文 20091215 增加
//异步通道回调函数
function XMLHTTPAsyncComplete(sRtnXml)
{
    //拆分sRtnXml并打到页面上的对应控件中去
    closeWaitingDiv(document);
	if (sRtnXml != "")
	{
		document.all("dw_1").style.backgroundColor = "#ffffff";
		var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
		xmlDom.loadXML(sRtnXml);

		var sRptStatus;
		var sPsrContent;
		var sPblContent;
		var sPsrFileName;
		var sPblFileName;
		var sError;

		if (xmlDom.documentElement != null)
		{
			if (xmlDom.documentElement.selectSingleNode("/xml/Error") == null)
			{
				document.all("txtRptStatus").value = "resultok";
				sRptStatus = xmlDom.documentElement.selectSingleNode("/xml/RptStatus").text;
				sPsrContent = xmlDom.documentElement.selectSingleNode("/xml/PsrContent").text;
				sPblContent = xmlDom.documentElement.selectSingleNode("/xml/PblContent").text;
				sPsrFileName = xmlDom.documentElement.selectSingleNode("/xml/PsrFileName").text;
				sPblFileName = xmlDom.documentElement.selectSingleNode("/xml/PblFileName").text;
			}
			else
			{
				document.all("txtRptStatus").value = "error";
				sError = xmlDom.documentElement.selectSingleNode("/xml/Error").text;
			}
		}

		document.all("txtPsrZipData").value = sPsrContent;
		document.all("txtPblZipData").value = sPblContent;
		document.all("txtClientPsrFilename").value = sPsrFileName;
		document.all("txtClientPblFilename").value = sPblFileName;
		document.all("txtError").value = sError;
		document.all("dw_1").style.display = "";
		doLoad();   
	}

}

//胡智文 20091215 增加
//检测文档对象doc 中是否存在element元素
//doc 文档对象 ，默认为当前document
//element 元素名称 ，默认为当前223    
var docEle = function(doc, element)
{
	return doc.getElementById(element) || false;
}


//胡智文 20091215 增加
//创建等待层
//strInfo 显示提示信息字符串
//doc 要覆盖的层
//intWidth 窗口长度
//胡智文 20091212 增加
function CreateLoadingDiv(strInfo, doc, intWidth)
{

	var m = "divLoadingUp", _id = "divLoading";
	if (!doc) doc = document;
	if (!intWidth) intWidth = 223;
	if (docEle(doc, _id)) doc.body.removeChild(docEle(doc, _id));
	if (docEle(doc, m)) doc.body.removeChild(docEle(doc, m));

	//mask遮罩层
	var newMask = doc.createElement("div");
	newMask.id = m;
	newMask.style.position = "absolute";
	newMask.style.zIndex = "1";
	_scrollWidth = Math.max(doc.body.scrollWidth, doc.documentElement.scrollWidth);
	_scrollHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight);
	newMask.style.width = _scrollWidth + "px";
	newMask.style.height = _scrollHeight + "px";
	newMask.style.top = "0px";
	newMask.style.left = "0px";
	newMask.style.background = "#ffffff";
	newMask.style.filter = "alpha(opacity=0)";
	newMask.style.opacity = "1";
	doc.body.appendChild(newMask);

	//新弹出层
	var newDiv = doc.createElement("div");
	newDiv.id = _id;
	newDiv.setAttribute("text-align", "center");
	newDiv.style.position = "absolute";
	newDiv.style.zIndex = "9999";
	newDiv.style.width = intWidth;
	newDiv.style.height = "36px";
	newDiv.style.top = (doc.body.scrollTop + doc.body.clientHeight / 2 + 36 / 2) + "px";
	newDiv.style.left = (doc.body.scrollLeft + doc.body.clientWidth / 2 - intWidth / 2) + "px";
	newDiv.style.background = "#ffffff";
	newDiv.style.border = "0px solid #860001";
	newDiv.style.padding = "5px";
	newDiv.innerHTML = "<div  style='f text-align:left;vertical-align:middle;width:100%; padding:0.5px' ><table><tr><td><img src='/Images/ajax-loading.gif' style='height:32px;width:32px; background-repeat:repeat;border:0px'/></td><td>&nbsp;<span  style='text-align:left;vertical-align:middle; font-variant:normal;font-style:normal;COLOR: #ff5a00; FONT-SIZE: 14px;FONT-WEIGHT: bold;'>" + strInfo + "</span></td><td><img src='/Images/ajax-loadernext.gif'/></td></tr></table></div>";
	doc.body.appendChild(newDiv);


}

//关闭，等待窗口
//doc 关闭等待窗口所属的文档对象，默认为当前document
//胡智文 20091212 增加
function closeWaitingDiv(doc)
{
	if (!doc) doc = document;
	if (docEle(doc, "divLoading")) doc.body.removeChild(docEle(doc, "divLoading"));
	if (docEle(doc, "divLoadingUp")) doc.body.removeChild(docEle(doc, "divLoadingUp"));
	return false;
}


//通过XMLHTTP通道不刷新页面从后台取数
//参数：sFile					-	打开文件
//		strBusinessType			-	业务对象
//		strBusinessInfo			-	业务信息
//		strPostStream			-	大容量业务参数
  function GetDataByXMLHTTPAsync(strFile, strBusinessType, strBusinessInfo, strPostStream)
  {	  
  	if (strFile == undefined || strFile == "") strFile = "/Pub_XmlHttp.aspx"
  	var rdNum = Math.random();
  	var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
  	var sUrl = strFile + "?p_businessType=" + escape(strBusinessType) + "&p_businessInfo=" + escape(strBusinessInfo) + "&rdnum=" + rdNum;
  	oHTTP.onreadystatechange = function()
  	{
  		if (oHTTP.readyState == 4)
  		{	 
  			if (oHTTP.status == 200)
  			{	 
  				var bSuccess = handleXMLErr(oHTTP.responseXML);
  				if (bSuccess)
  				{
  					if (oHTTP.responseText == "服务器超时") window.navigate("/ErrPage.aspx?errid=001");
  					XMLHTTPAsyncComplete(oHTTP.responseText);
  				}
  				else
  				{
  					alert("操作失败，请关闭重试！");
  					XMLHTTPAsyncComplete("");
  					document.all("dw_1").style.display = "";
  				}
  			}
  			else
  			{
  			    alert("网络错误！");
  			    document.all("dw_1").style.display = "";
  			}
  		}
  	};

  	if (strPostStream == undefined)
  	{
  		oHTTP.open("GET", sUrl, true );
  		oHTTP.send();
  	}
  	else
  	{
  		oHTTP.open("POST", sUrl, true);
  		oHTTP.send(strPostStream);
  	}
  }
//
function doLoad()
{   
	switch (document.getElementById("txtOpenType").value)
	{
		case "Print":
			document.getElementById("trmenu").height = "25px";
			document.getElementById("trmenubar").style.display="none";
			if(document.getElementById("txtOpenData").value!="")
			{
			   try
			   { 
			     var strPathTmp=document.getElementById("txtOpenData").value;
			     var iLastIndex=strPathTmp.lastIndexOf("\\");
			     document.getElementById("txtClientAddr").value=strPathTmp.substring(0,iLastIndex);
			     document.getElementById("txtClientPsrFileName").value=strPathTmp.substring(iLastIndex+1);
			   }
			   catch(e)
			   {			   
			   } 			
			}
			break;
		case "Drill":
			if (document.all("query")!=null)
			{
				document.all("query").action = "DonotConditionQuerey()";
				document.all("query").children(1).style.color = "#808080";
				document.all("tb_query").onclick = DonotConditionQuerey;
				document.all("tb_query").style.filter = "gray";
			}
			break;
		case "Screen":
		
			document.getElementById("trmenu").height = "25px";
			document.getElementById("trmenubar").style.display="none";
			
			if (document.all("query")!=null)
			{
				document.all("query").action = "DonotConditionQuerey()";
				document.all("query").children(1).style.color = "#808080";
				document.all("tb_query").onclick = DonotConditionQuerey;
				document.all("tb_query").style.filter = "gray";
			}
			break;
	}	

	//3 报表处理
	/*txtRptStatus的值
	'pending            第一次打开              后端初始状态结果，后端使用
	'ready              报表基本信息准备好      后端生成状态结果，前端使用
	'paramok            参数已经准备好          前端生成状态结果，后端使用
	'resultok           结果已经准备好          后端生成状态结果，前端使用
	'initerror          初始化错误              后端生成状态结果，前端使用
	'error              错误                    后端生成状态结果，前端使用
	*/
	var rptstatus = document.getElementById("txtRptStatus");
	switch (rptstatus.value)
	{
		case "ready":
			//sbb11 2007-02-25 需要判断opentype，如果非query则需要填充值
			
			switch (document.getElementById("txtOpenType").value)
			{
				case "Query":
					if (OpenParamWindow() == undefined )
					{
						window.close();
						return;
					}	
					break;
				case "Screen":
					SetOpenDataToParam();
					break;
				case "SilencePrint":
					SetOpenDataToParam();
					break;
				case "Drill":
					
					SetOpenDataToParam();
					break;
			}

			//3.1.2 检查参数
			if (CheckParam() == true)
			{
				rptstatus.value = "paramok";
				//__doPostBack("","");
				return "paramok";
			}
			else
			{
				alert("报表参数不完整!");
			}

			break;
			
		case "resultok":
		
			//根据权限处理菜单
			//处理打印权限
			if (document.getElementById("txtIsPrn").value == "0" || document.getElementById("txtIsPrn").value=="2" )
			{
					if (document.all("print")) document.all("print").style.display = "none";
					if (document.all("tb_print")) document.all("tb_print").disabled = true;
					
					if (document.all("tprint")) document.all("tprint").style.display = "none";
					if (document.all("tb_tprint")) document.all("tb_tprint").disabled = true;
			}
			//处理导出数据权限
			if (document.getElementById("txtIsPrn").value == "0" || document.getElementById("txtIsPrn").value=="1" )
			{
					if (document.all("exportExcel")) document.all("exportExcel").style.display = "none";
					if (document.all("tb_exportExcel")) document.all("tb_exportExcel").disabled = true;
					
					if (document.all("exportData")) document.all("exportData").style.display = "none";
					if (document.all("tb_exportData")) document.all("tb_exportData").disabled = true;
			
			}
			
		
			//3.2	结果信息准备状态
			var sPsrAddr;
			
			//3.2.1 处理结果路径
			switch (document.getElementById("txtOpenType").value)
			{
				case "Print":
					sPsrAddr = document.getElementById("txtOpenData").value;
					break;	

				default:
			        
					document.getElementById("txtClientAddr").value = MyZip.UnzipToFile(document.getElementById("txtPsrZipData").value);
					document.getElementById("txtPsrZipData").value = "";
				
					if (document.getElementById("txtPblZipData").value.length > 0)
					{
						MyZip.UnzipToFile(document.getElementById("txtPblZipData").value);
						document.getElementById("txtPblZipData").value = "";
					}
					
					sPsrAddr = document.getElementById("txtClientAddr").value + '\\' + document.getElementById("txtClientPsrFileName").value;
				
			}
			
	
			//3.2.2 打开方式
			if (document.getElementById("txtRptType").value == "9")		
			{
				//b) 使用报表设计器打开预览（目前针对交叉型报表）
				document.all("MyZip").Psr2Xls(sPsrAddr,"115","-w");
				parent.window.close();
			}
			else
			{
				switch (document.getElementById("txtOpenType").value)
				{
					case "SilencePrint":
						//a) 静默打印
						var copys = parseInt(GetOpenData("copys"));
						
						for (var i=0;i<copys;i++)
						{
							document.all("MyZip").Psr2Xls(sPsrAddr,"115","-p");
						}
						break;
					case "Print":
						//打印模式
						if (sPsrAddr.length>0)
							document.dw_1.DataWindowObject = sPsrAddr;
						
						dw_1.Modify("DataWindow.Print.Preview = 'YES'");
						dw_1.Modify("DataWindow.Print.Preview.Rulers='yes'");	
						break;				
					case "Screen":
						//屏幕报表
						if (sPsrAddr.length>0)
							document.dw_1.DataWindowObject = sPsrAddr;
						
						dw_1.Modify("DataWindow.Print.Preview = 'YES'");
						dw_1.Modify("DataWindow.Print.Preview.Rulers='yes'");	
						break;				
					default:
						//c) web预览
						//加载改变打印机篇幅的功能
						//MyZip.InstallDevice();
						
						if (sPsrAddr.length>0)
							document.dw_1.DataWindowObject = sPsrAddr;
						
						//设置预览纸张大小(9--A4,8--A3)
//						if (document.all("dw_1").describe("DataWindow.Print.Paper.Size") == 9 )
//							MyZip.SetPaperSize(2970,2970);
//						else
//							MyZip.SetPaperSize(4200,4200);
						
						dw_1.Modify("DataWindow.Print.Preview = 'YES'");
						
						//报表数据
						strData = dw_1.Describe("DataWindow.Data");
						arrRows = splitToRow(strData);
						
						//对dw操作完成后才释放打印机篇幅设置功能
						//MyZip.UnInstallDevice();

				}
			}			
			
			dw_1.focus();
			
			break;		
		case "initerror":
			//3.3 初始化信息失败
			alert("报表基本信息读取失败!");
			rptstatus.value = "pending";
			window.close();
			
			break;
		case "error":
			//3.4 其他信息失败
			alert(document.getElementById("txtError").value);
			rptstatus.value = "ready";
		
			break;
	}

}


function window_onbeforeunload()
{
	//对dw操作完成后才释放打印机篇幅设置功能
	//MyZip.UnInstallDevice();
}		


//===========================报表视图相关动作==============================
//BtnFirst_onclick			第一页
//BtnPrevious_onclick		上一页
//BtnNext_onclick			下一页
//BtnLast_onclick			最后一页
//BtnRuler_onclick			标尺
//BtnDisplayScale_onclick	预览缩放
//BtnRptScale_onclick		对象缩放
function BtnPrintPreview_onclick()
{
	if (document.getElementById("txtRptStatus").value=="resultok")
	{
	
	
		var w = screen.width;
		var h = screen.height; 
		var sTitle;
		var sFile;
		var sParamList;
		var sIsPrn;
		
		sTitle = "报表打印";
		sFile = "/Report/ReportView.aspx";

		sParamList = "OpenType=Print&rptid" + escape(document.getElementById("txtRptId").value);
		sParamList = sParamList + "&isprn=" + escape(document.getElementById("txtIsPrn").value);
		sParamList = sParamList + "&OpenData=" + escape(document.getElementById("txtClientAddr").value + '\\' + document.getElementById("txtClientPsrFileName").value);
		
		openMyDlg(sTitle,sFile,sParamList,"",w.toString(),h.toString());
	}
	else
	{
		alert("报表未生成");
	}
}

function BtnFirst_onclick() {
	var ll_count=document.all("dw_1").rowcount();
	if (ll_count> 0){
		document.all("dw_1").ScrollToRow(1) ;
	}
}

function BtnPrevious_onclick() {
document.all("dw_1").ScrollPriorPage ( )
}

function BtnNext_onclick() {
	document.all("dw_1").ScrollNextPage();
}

function BtnLast_onclick() {
	var ll_count=document.all("dw_1").rowcount();
	if (ll_count> 0){
		document.all("dw_1").ScrollToRow(ll_count) ;
	}
}

function BtnRuler_onclick() 
{
	var ls_tmp=document.all("dw_1").Describe("DataWindow.Print.Preview.Rulers");
	if (ls_tmp == "yes")
	{
		document.all("dw_1").modify("DataWindow.Print.Preview.Rulers='no'");
	} 
	else 
	{
		document.all("dw_1").modify("DataWindow.Print.Preview.Rulers='yes'");	
	}
}

var RptZoom = 100;
function BtnDisplayScale_onclick(iZoom)
{
	var Zoom = parseInt(parseInt(iZoom) * 1 );

    try{document.all.Zoom.setValue(Zoom);}catch (e){}
	var ls_modify = "DataWindow.Print.Preview.Zoom=" + Zoom;
	//改变打印机篇幅
	//document.all.MyZip.InstallDevice();
	
//	if (document.all("dw_1").describe("DataWindow.Print.Paper.Size") == 9 )
//		MyZip.SetPaperSize(2970,2970);
//	else
//		MyZip.SetPaperSize(4200,4200);
			
	document.all("dw_1").modify(ls_modify);	
	
	//document.all.MyZip.UnInstallDevice();
}

function BtnRptScale_onclick(iZoom)
{
	RptZoom = parseInt(parseInt(RptZoom) + iZoom);

	var ls_modify = "DataWindow.Zoom=" + RptZoom;
	document.all("dw_1").modify(ls_modify);	
}


//条件查询
function BtnConditionQuerey_onclick()
{   
	if (document.getElementById("txtOpenType").value == "Query")
	{
		if (OpenParamWindow() == undefined )
		{
		}
		else
		{
			document.getElementById("txtRptStatus").value="ready";
			if (CheckParam() == true)
			{
				document.getElementById("txtRptStatus").value = "paramok";
				//__doPostBack("","");
				GetRpt();
                //打开报表
                //doLoad();    
			}
			else
			{
				alert("报表参数不完整!");
			}
		}
	}
}


//导出Excel
function BtnExportExcel_onclick()
{
	//先校验
	var ls_path = document.getElementById("txtClientAddr").value + '\\' + document.getElementById("txtClientPsrFileName").value;
	var sRtn = document.all("MyZip").CheckPsr2Xls(ls_path,"115");
	switch (sRtn)
	{
		case 0:		//成功
			document.all("MyZip").Psr2Xls(ls_path,"115");
			return true;
			break;
		case -1:	//缺少工具
			if (confirm("您未安装 Excel 转换工具！\n\n确定：下载并安装 Excel 转换工具。\n取消：退出操作。")==true)
			{
				location.replace('/ActiveX/PBReport/psrview_setup.exe');	
			}
			
			return false;				
			break;
		case -2:	//缺少报表文件
			alert("报表文件不存在，请与系统管理员联系！");
			return false;
			break;
	}	
}


//导出数据（快速）
function BtnExportData_onclick()
{
	//先校验
	var ls_path = document.getElementById("txtClientAddr").value + '\\' + document.getElementById("txtClientPsrFileName").value;
	var sRtn = document.all("MyZip").CheckPsr2Xls(ls_path,"115");
	switch (sRtn)
	{
		case 0:		//成功
			document.all("MyZip").Psr2Xls(ls_path,"115","-d");
			return true;
			break;
		case -1:	//缺少工具
			if (confirm("您未安装导出转换工具！\n确定：下载安装导出转换工具。\n取消：退出操作。")==true)
			{
				location.replace('/ActiveX/PBReport/psrview_setup.exe');	
			}
			
			return false;				
			break;
		case -2:	//缺少报表文件
			alert("报表文件不存在，请与系统管理员联系！");
			return false;
			break;
	}	
}

function BtnSetPrinter_onclick()
{   
	   document.all("MyZip").SetPrinter();	
}


//打印...
function BtnPrint_onclick() 
{
	ReturnValue = window.showModalDialog( "/report/ReportPrint.aspx", document, "dialogHeight:258px; dialogWidth:488px; help:no; status:no") ;
	
	if ( ReturnValue == "ok" ) 
	{
		document.all("dw_1").print(true);
	}
}

//套打
function BtnTPrint_onclick() 
{
	ReturnValue = window.showModalDialog( "/report/ReportPrint.aspx", document, "dialogHeight:258px; dialogWidth:488px; help:no; status:no") ;
	
	var li_rtn;
	li_rtn = document.all("dw_1").GetFullState();
	var dwstatus = document.all("dw_1").GetFullStateBlob();		//真正的数据
		
	document.all("dw_2").SetFullState(dwstatus);
		
	if ( ReturnValue == "ok" ) 
	{
		SetTPrintObject();
		document.all("dw_2").print(true);
	}
}

function SetTPrintObject()
{
	var attrprocess = document.all("dw_2").describe("DataWindow.Processing");
	if (attrprocess == 1)
		document.all("dw_2").modify("DataWindow.Grid.Lines=1");
		
	var objects = document.all("dw_2").describe("DataWindow.Objects");
	var objtype;
	var obj = new Array();
	var i ;
	
	obj = objects.split("\t");
	
	for (i=0;i<obj.length - 1 ;i++)
	{
			
		objtype = document.all("dw_2").describe(obj[i] + ".type");
		if (objtype == "bitmap" || objtype == "line" || obj[i].substr(0,3)=="td_")
		{
			document.all("dw_2").modify(obj[i] + ".visible=0");
		}
	}
	
	//由于套打时，打印是用dw_2做为数据窗口，但在设置时，是针对dw_1的设置，所以套打时，全部为默认值，即不管打印设置时，进行了何种设置，都会按默认值打印。
	//下面的代码是直接将打印设置中针对dw_1的信息赋值给dw_2.可能此函数原来的代码已有这方面的考虑，但最终漏了这部分的内容。由于时间关系，在此不做研究，如果以后有时间，可以研究后再与上面的代码整合。
	try
	{	
		document.all("dw_2").modify("DataWindow.Print.Page.Range ='" + document.all("dw_1").describe("DataWindow.Print.Page.Range") + "'");
		document.all("dw_2").modify("DataWindow.Print.Copies ='" +  document.all("dw_1").describe("DataWindow.Print.Copies") + "'");
		document.all("dw_2").modify("DataWindow.Print.Orientation='" + document.all("dw_1").describe("DataWindow.Print.Orientation") + "'");
		document.all("dw_2").modify("DataWindow.Print.Page.RangeInclude='" + document.all("dw_1").describe("DataWindow.Print.Page.RangeInclude") + "'");
		document.all("dw_2").modify("DataWindow.Print.Paper.Size='" + document.all("dw_1").describe("DataWindow.Print.Paper.Size") + "'");
	}
	catch(e)
	{}
}
//================================其他菜单操作==========================================
//About			打开关于窗口

function About(o)
{   
	_oCalInput = o;			//返回值填入该对象
	_oCalPopUp = window.createPopup();
	
	_oCalPopUp.document.body.innerHTML = document.getElementById("dvabout").innerHTML;
	_oCalPopUp.show(200, 200, 424, 300, null);
	
}

//================================报表参数相关方法===================================
//GetCustomParamHeight		计算自定义过滤窗口的高度
//OpenParamWindow			打开自定义过滤窗口
//CheckParam				检查报表变量是否已经取值
function GetCustomParamHeight(strcustomparam)
{
	var sRtn=0;
	var xmlDom = new ActiveXObject("Microsoft.XMLDOM"); 
			
	xmlDom.async=false; 
	xmlDom.loadXML(strcustomparam);
	
	if(xmlDom.parseError.errorCode == 0)
	{
		var nodes;
		var i ;

		nodes = xmlDom.selectNodes("//customparam");
	
		for (i=0;i<nodes.length ;i++)
		{
			if (nodes(i).selectSingleNode("varpurpose").text == '辅助录入' || nodes(i).selectSingleNode("varpurpose").text=='')
			{
				sRtn  = sRtn + 35;
			}
		}
	}
	sRtn = sRtn + 100;
	delete(xslDom);
	return sRtn;
}


/*
功能根据报表情况是否打开报表过滤窗口
实现思路：
1 判断报表是否有可供查询字段
2 判断报表是否有自定义过滤条件

返回值：
	nothing 取消查询
	ok      确定查询
*/
function OpenParamWindow()
{
	var gp;
	var rtn

	if (document.getElementById("txtQueryCols").value.length >0 )
		gp = 1;
	else
		gp = 0;

	if (document.getElementById("txtCustomParam").value.length > 0 && (document.getElementById("txtCustomParam").value.indexOf("<varpurpose></varpurpose>")>=0 || document.getElementById("txtCustomParam").value.indexOf("<varpurpose>辅助录入</varpurpose>")>=0))
	{
		document.getElementById("txtCustomFormHtml").value = XmlToHTML(document.getElementById("txtCustomParam").value,"/report/rptxsl/customparam.xsl");
		
		var h = GetCustomParamHeight(document.getElementById("txtCustomParam").value);
		
		//在通用过滤窗口打开后判断是否有txtQueryCols的值来决定是否相似通用过滤值
		rtn = window.showModalDialog("/report/RptCustomParam.aspx",document,"dialogHeight:" + (h+35) + "px;dialogWidth:300px;scroll:no;status:no;help:no");
		if (rtn=="gp")  
		{
			document.getElementById("txtGeneralParam").value="";		
			gp = 1;
		}
		else if(rtn==undefined)
			return undefined;
		else
		{
		    document.getElementById("txtGeneralParam").value="";
			gp = 0;
		}
	}
	
	if (gp==1)
		return window.showModalDialog("/report/RptGeneralParam.aspx",document,"dialogHeight:400px;dialogWidth:620px;scroll:no;status:no;help:no");
	else
		return "ok";
}

/*
功能：检查报表参数是否齐备
实现思路：
1 检查generalparam中是否还存在报表变量
2 检查customparam中是否存在空的value
*/
function CheckParam()
{
	//判断generalparam中是否存在报表变量或者字段名称
	if (document.getElementById("txtGeneralParam").value.toLowerCase().indexOf(":var_")>=0) return false;
	if (document.getElementById("txtGeneralParam").value.toLowerCase().indexOf("[")>=0) return false;
	if (document.getElementById("txtGeneralParam").value.toLowerCase().indexOf("]")>=0) return false;
	
	//判断customparam中是否存在报表
	var xmlDom = new ActiveXObject("Microsoft.XMLDOM"); 
	xmlDom.loadXML(document.getElementById("txtCustomParam").value);
	
	var nodes = xmlDom.selectNodes("//customparam");
	
	for(var i=0;i<nodes.length;i++)
	{
		if(nodes(i).selectSingleNode("./varvalue").text=="" && nodes(i).selectSingleNode("./varpurpose").text == "辅助录入")
		{
			return false;
		}
	}
	return true;			
}

//提取OpenData中的数据
function GetOpenData(strparam)
{
	var stropendata;
	stropendata = document.getElementById("txtOpenData").value;
	
	if (stropendata=="")
	{
		return "";
	}
	else
	{
	
		var xmlDom = new ActiveXObject("Microsoft.XMLDOM"); 
		xmlDom.loadXML(stropendata);
		
		var paramdata = xmlDom.selectSingleNode("/xml/" + strparam.toString());
		if (paramdata)
		{
			return paramdata.text;
		}
		else
		{
			return ""
		}
	}
}

//设置OpenData中的数据到param
function SetOpenDataToParam()
{
	//系统变量在屏幕报表中需要自行设定值
	var customparamvalue;
	var generalparamvalue;
	
	customparamvalue = GetOpenData("customparamvalue");
	generalparamvalue = GetOpenData("generalparamvalue");
	
	//处理generalparam
	if (generalparamvalue.length>0)
	{
		document.getElementById("txtGeneralParam").value = generalparamvalue.replace(/\*plus\*/g,"+");
	}
	
	//处理customparam
	if (document.getElementById("txtCustomParam").value.length>0&&customparamvalue.length>0)
	{
		var arrcpv = customparamvalue.split("|");
		
		var xmlDom = new ActiveXObject("Microsoft.XMLDOM"); 
			
		xmlDom.async=false; 
		xmlDom.loadXML(document.getElementById("txtCustomParam").value);
		
		var nodescpv = xmlDom.selectNodes("//customparam");
		
		if (arrcpv.length==nodescpv.length)
		{
			for (i=0;i<nodescpv.length;i++)
			{
				var arrval = arrcpv[i].split("$");
				
				if (arrval.length>1)
				{
					nodescpv(i).selectSingleNode("./varvalue").text = arrval[0];
					nodescpv(i).selectSingleNode("./vardispvalue").text = arrval[1];
				}
				else
				{
					nodescpv(i).selectSingleNode("./varvalue").text = arrcpv[i];
					nodescpv(i).selectSingleNode("./vardispvalue").text = arrcpv[i];
				}
				
			}
		}
		document.getElementById("txtCustomParam").value = xmlDom.xml;
	}
}


//处理层层深化变量只用来处理[]类型参数
//sParam	-- 被替换的变量
//o			-- 报表dw对象
//name		-- 点击报表对象的名称
//row		-- 报表中被激活的是第几行
function of_translation_drill(sParam, dw, name, row , mode)
{

	var colcount = parseInt(dw.Describe("DataWindow.Column.Count"));
	var ls_coltype;
	var lx = 0;
	var ly = 0;
	var ObjectID, arrColumnData, ldc_tmp;
	var ls_dwoname, sType;
	var sMathType = "deci,numb,long";

	do
	{
		lx = sParam.indexOf("[", ly);
		if (lx > -1)
		{
			ly = sParam.indexOf("]", lx);
			ls_dwoname = sParam.substr(lx+1, ly-lx-1);
			
			//this关键字
			if (ls_dwoname == "this")
			{
				ls_coltype = dw.Describe(name + ".type");		//点击对象的类型
				
				re = new RegExp("\\[this\\]","g");
				if (ls_coltype == "column")
				{
					if (row > 0)
					{
						ObjectID = dw.Describe(name + ".ID");
						arrColumnData = arrRows[row - 1].split("\t");
						ldc_tmp = arrColumnData[ObjectID - 1];
						
						ls_coldbtype = dw.describe(name + ".coltype");
						if(sMathType.indexOf(ls_coldbtype.substr(0, 4)) > 0 || mode==1)
						{
							sParam = sParam.replace(re, ldc_tmp);
							ly = ly + (ldc_tmp - re);
						}
						else
						{
							sParam = sParam.replace(re, "'" + ldc_tmp + "'");
							//sParam = sParam.replace(re, ldc_tmp );

							ly = ly + (ldc_tmp + 2 - re);
						}
					}
				}
				else if (ls_coltype == "text")
				{
					if (mode==1)
						sParam = sParam.replace(re, dw.Describe(name + ".text") );
					else
						sParam = sParam.replace(re, "'" + dw.Describe(name + ".text") + "'");

					ly = ly + (ldc_tmp + 2 - re);
				}			
			}	
			else
			{
				ls_coltype = dw.Describe(ls_dwoname + ".type");		//要替换对象的类型
				
				re = new RegExp("\\[" + ls_dwoname + "\\]","g");
				if (ls_coltype == "column")
				{
					if (row > 0)
					{
						for (i=1; i<=colcount; i++)
						{
							if (dw.Describe("#" + i.toString() + ".name") == ls_dwoname)
							{
								ObjectID = dw.Describe(ls_dwoname + ".ID");
								arrColumnData = arrRows[row - 1].split("\t");
								ldc_tmp = arrColumnData[ObjectID - 1];

								ls_coldbtype = dw.describe("#" + i.toString() + ".coltype");
								if(sMathType.indexOf(ls_coldbtype.substr(0, 4)) > 0 || mode==1)
								{
									sParam = sParam.replace(re, ldc_tmp);
									ly = ly + (ldc_tmp - re);
								}
								else
								{
									sParam = sParam.replace(re, "'" + ldc_tmp + "'");
									//sParam = sParam.replace(re, ldc_tmp );
									ly = ly + (ldc_tmp + 2 - re);
								}
								break;
							}
						}
					}
				}
				else if (ls_coltype == "text")
				{
					if (mode==1)
						sParam = sParam.replace(re, dw.Describe(ls_dwoname + ".text") );
					else
						sParam = sParam.replace(re, "'" + dw.Describe(ls_dwoname + ".text") + "'");
						

					ly = ly + (ldc_tmp + 2 - re);
				}
			}
		}
	}
	while (lx != -1)
	
	return sParam;
}


//替换字符串中的报表变量到具体的值
function of_translation_rptvar(customparamvalue,customparam,mode)
{
	
	if (customparam.length>0)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(customparam); 
		
		var re = new RegExp(":\\w+","ig"); 
		var cps = customparamvalue.match(re); 

		if (cps)
		{
			for(var i=0;i<cps.length;i++)
			{
				
				var node = xmlDoc.selectSingleNode("//customparam[varname='" + cps[i].substr(1,cps[i].length)  + "']");
				if(node)
				{
					if (mode==1 || node.selectSingleNode("./vartype").text == '数值')
						customparamvalue = customparamvalue.replace( cps[i] , node.selectSingleNode("./varvalue").text + "$" + node.selectSingleNode("./vardispvalue").text  );
					else
						customparamvalue = customparamvalue.replace( cps[i] , "'" + node.selectSingleNode("./varvalue").text.replace(",","','") + "'" + "$" + "'" + node.selectSingleNode("./vardispvalue").text.replace(",","','") + "'");
				}
			}
		}
	}

	return customparamvalue;
}


//初始化数据
var strData ,arrRows;
function splitToRow(strData)
{
	var arrRow;
	arrRow = strData.split("\r\n");
	return arrRow;
}

function DonotConditionQuerey()
{
	alert("层层深化报表或屏幕报表不允许进行条件查询！");
}


//修改布局
function designPage()
{
	document.all("saveformat").style.display = "block";
	document.all("designformat").style.display = "none";	

	document.all("tb_saveformat").disabled = false;
	document.all("tb_designformat").disabled = true;
	
	setDesign("1");
	
}

function setDesign(bvalue)
{
	//合同认购书设置为可调整布局
	
	var objects = document.all("dw_1").describe("DataWindow.Objects");
	var objtype,objvisible;
	var obj = new Array();
	var i ;
	
	obj = objects.split("\t");
	
	for (i=0;i<obj.length ;i++)
	{
			
		objtype = document.all("dw_1").describe(obj[i] + ".type");
		objvisible = document.all("dw_1").describe(obj[i] + ".visible");
		
		if ((objtype == "column"  || objtype == "text" || objtype == "compute") && obj[i].substr(0,3)!="td_" && objvisible=="1")
		{
			document.all("dw_1").modify(obj[i] + ".Moveable=" + bvalue);
		}
	}
}

function savePage()
{

	
	var saveXML;
	var objects = document.all("dw_1").describe("DataWindow.Objects");
	var objtype,objvisible;
	var obj = new Array();
	var i ;
	
	obj = objects.split("\t");

	saveXML = "<report top='" + document.all("dw_1").describe("DataWindow.Print.Margin.Top") + "' " 
			+ "bottom='" + document.all("dw_1").describe("DataWindow.Print.Margin.Bottom") + "' " 
			+ "left='" + document.all("dw_1").describe("DataWindow.Print.Margin.Left") + "' " 
			+ "right='" + document.all("dw_1").describe("DataWindow.Print.Margin.Right") + "' " 
			+ ">";
		
	for (i=0;i<obj.length;i++)
	{
			
		objtype = document.all("dw_1").describe(obj[i] + ".type");
		objvisible = document.all("dw_1").describe(obj[i] + ".visible");
		
		if ((objtype == "column"  || objtype == "text" || objtype == "compute") && obj[i].substr(0,3)!="td_" && objvisible=="1")
		{
			saveXML += "<object name='" + document.all("dw_1").describe(obj[i] + ".name") + "' " + 
					  " x='" + document.all("dw_1").describe(obj[i] + ".x") + "'" +
					  " y='" + document.all("dw_1").describe(obj[i] + ".y") + "'>" + 
					  "</object>";
		}
	}
	
	saveXML += "</report>";
	
	//alert(saveXML);
	var strReturn
	strReturn = GetDataFromXMLHTTP("/report/rpthttp.aspx","SavePage",document.getElementById("txtRptID").value,"" , saveXML);
		if (strReturn=="-1") 
		{
			alert("保存失败！");
		}
		else
		{
			alert("保存成功！");
			
			document.all("saveformat").style.display = "none";
			document.all("designformat").style.display = "block";	
				
			document.all("tb_saveformat").disabled = true;
			document.all("tb_designformat").disabled = false;	
			
			setDesign("0")
		}
}